package com.example.demo.lock;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class TestCyclicBarrier {

    public static void main(String[] args) {
        CyclicBarrier cb = new CyclicBarrier(7,()->{
            System.out.println("召唤神龙");
        });
        for (int i = 0;i<7;i++){
            int finalI = i;
            new Thread(()->{
                try {
                    cb.await();
                    System.out.println(finalI);
                } catch (InterruptedException | BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();
        }
        System.out.println("等待神龙");
    }

}
